local skill = fk.CreateSkill {
  name = "lvshi__secret_advance_skill",
}

Fk:loadTranslationTable{
  ["#secret_advance-give"] = "暗度陈仓：请交给 %dest %arg张手牌",
  ["@@secret_advance-turn"] = "暗度",
}
local ls = require "packages/lvshi/utility"
skill:addEffect("cardskill", {
  prompt = "#lvshi__secret_advance_skill",
  target_num = 1,
  mod_target_filter = function(self, player, to_select, selected, card)
    return to_select ~= player and not to_select:isAllNude()
  end,
  target_filter = Util.CardTargetFilter,
  on_use = function(self, room, use)
    local choice = ls.strategytrickuse(use.from, use.card, "secret_advance_scheme", "secret_advance_courage")
    use.extra_data = use.extra_data or {}
    use.extra_data.strategy = choice
  end,
  on_effect = function(self, room, effect)
    local player = effect.from
    local target = effect.to
    if player.dead or target.dead or target:isAllNude() then return end
    local n = 2
    if effect.extra_data.strategy == "secret_advance_scheme" or effect.card:getMark("strategyscheme") > 0 then
      n = 4
    end
    local cards = room:askToChooseCards(player, {
      target = target,
      min = 1,
      max = n,
      flag = "hej",
      skill_name = skill.name,
    })
    room:obtainCard(player, cards, false, fk.ReasonPrey, player, skill.name)
    if not player.dead and not target.dead or player:isKongcheng() then
      local n = math.min(#cards, player:getHandcardNum())
      cards = room:askToCards(player, {
        min_num = n,
        max_num = n,
        include_equip = false,
        skill_name = skill.name,
        prompt = "#secret_advance-give::"..target.id..":"..n,
        cancelable = false,
      })
      room:obtainCard(target, cards, false, fk.ReasonGive, player, skill.name)
      if not player.dead and not target.dead and effect.extra_data.strategy == "secret_advance_courage" then
        room:addTableMark(target, "@@secret_advance-turn", player.id)
      end
    end
  end,
})

skill:addEffect("targetmod", {
  global = true,
  bypass_distances = function(self, player, skill, card, to)
    return card and table.contains(to:getTableMark("@@secret_advance-turn"), player.id)
  end,
})

return skill
